package com.boot;

import com.boot.config.OtherConfig;
import com.boot.config.UpConfig;
import com.boot.config.a.A1;
import com.boot.config.a.A2;
import org.springframework.boot.SpringApplication;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;

/**
 * @author
 * @date 2025-07-27
 * @Description
 */
public class MainApplication {
    public static void main(String[] args) {
        //随着程序启动，也要启动springboot
        ConfigurableApplicationContext context = SpringApplication.run(UpConfig.class, args);
        for (String name : context.getBeanDefinitionNames()) {
            System.out.println(name);
        }
//        OtherConfig otherConfig = (OtherConfig) context.getBean("com.boot.config.OtherConfig");
        OtherConfig otherConfig = (OtherConfig) context.getBean("otherConfig"); // 测试使用  @Configuration 标注注解 拿到的是 代理对象 com.boot.config.OtherConfig$$EnhancerBySpringCGLIB$$a6e42e63@5bf61e67
        System.out.println(otherConfig.getClass().getName());
        // 测试通过 @Configuration 修饰之后 a1 对象会产生多少个
        A1 a1 = (A1) context.getBean("a1");
        A2 a2 = (A2) context.getBean("a2");
        System.out.println(a1==a2.getA());

    }
}
